package com.aqs.demo;

import java.util.concurrent.locks.AbstractQueuedSynchronizer;

public class SingleHandlerLock {
    private Sync sync = new Sync();
    private static class Sync extends AbstractQueuedSynchronizer{
        @Override
        protected boolean tryAcquire(int arg) {
            return compareAndSetState(0,1);
        }
        @Override
        protected boolean tryRelease(int arg) {
            setState(0);
            return true;
        }

    }
    public void lock(){
        sync.acquire(1);
    }

    public void unlock(){
        sync.release(1);
    }
    
}
